<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="jquery1.9/jquery-1.9.0.js"></script>
    <style>
        .container{
            width:600px;
            height:400px;
            border:1px solid #ccc;
        }
        .mydiv{
            width:80px;
            height: 80px;
        }
    </style>
</head>
<body>
    <input type="button" value="开始" onclick="doMove()">
    <div class="container">
        <div class="mydiv d1"><img src="images/heihei.gif" alt=""></div>
        <div class="mydiv d2"><img src="images/heihei.gif" alt=""></div>
        <div class="mydiv d3"><img src="images/heihei.gif" alt=""></div>
        <div class="mydiv d4"><img src="images/heihei.gif" alt=""></div>
        <div class="mydiv d5"><img src="images/heihei.gif" alt=""></div>
    </div>
    <script>
        function moveDiv(params,time,divJq){
            var p=new Promise(function(resolve,reject){
                divJq.animate(params,time,resolve);
            });
            return p;
        }
        function doMove(){
             //获取jQuery对象
            var d1=$(".d1");
            var d2=$(".d2");
            var d3=$(".d3");
            var d4=$(".d4");
            var d5=$(".d5");
            var p=moveDiv({"margin-left":"100px"},1000,d1);
            var p2=p.then(function(){
                var pp=moveDiv({"margin-left":"200px"},1000,d2);
                return pp;
            });
            p2.then(function(){
                var pp=moveDiv({"margin-left":"300px"},1000,d3);
                return pp;
            })
            .then(function(){
                return moveDiv({"margin-left":"400px"},1000,d4);
            })
            .then(function(){
                return moveDiv({"margin-left":"500px"},1000,d5);
            })
            .then(function(){
                return moveDiv({"margin-left":"0px"},1000,d5);
            })
            .then(function(){
                return moveDiv({"margin-left":"0px"},1000,d4);
            })
            .then(function(){
                return moveDiv({"margin-left":"0px"},1000,d3);
            })
            .then(function(){
                return moveDiv({"margin-left":"0px"},1000,d2);
            })
            .then(function(){
                return moveDiv({"margin-left":"0px"},1000,d1);
            });
         


        }
    </script>
</body>
</html>